<?php

/**
 *
 * @package    symfony
 * @subpackage plugin
 * @author     Nick Winfield <enquiries@superhaggis.com>              
 * @version    SVN: $Id$
 */

// autoloading for plugin lib actions is broken as at symfony-1.0.2
require_once(dirname(__FILE__). '/../lib/BasesfSimpleForumActions.class.php');

class sfSimpleForumActions extends BasesfSimpleForumActions {

    public function executeEditPost(sfWebRequest $request){
        $id = $request->getParameter('id');
        $this->topic_id = $request->getParameter('topic_id');
        $this->topic_title = $request->getParameter('stripped_title');

        $user_id = $this->getUser()->getGuardUser()->getId();

        $this->forward404Unless($id);
        $this->forward404Unless($this->topic_id);
        $this->forward404Unless($this->topic_title);

        $currentForumPost = Doctrine::getTable('sfSimpleForumPost')->getCurrentForumPost($id, $user_id)->fetchOne();
        $this->forward404Unless($currentForumPost);

        $this->form = new EditForumPostForm($currentForumPost);
        $this->form->setDefault('content', $currentForumPost['content']);

        isicsBreadcrumbs::getInstance()->addItem('Editer ce commentaire', '#');
        $response = $this->getResponse();
        Utils::setSlogTitle('Editer ce commentaire', $response);

        if ($request->isMethod('post')) {
          $values = $request->getParameter($this->form->getName());
          $this->form->bind($values);

          if($this->form->isValid()){
              $this->form->save();
              
              $this->redirect('@forum_message?id=' . $id);
          }
        }
    }
}
